Windows Script Host object model

The Windows Script Host (WSH) environment includes a built-in library, WScript, and four COM (Component Object Model)-based libraries: WshShell, WshNetwork, WshController and the Scripting Runtime Library. Together, WScript, WshShell, WshNetwork and WshController are referred to as the WSH Objects. Your scripts access the functionality of these libraries through the WSH Object Model.

Scripts use object models to access features of COM-based libraries. In COM-based libraries an object model documents the features of the library. Scripts call an object's methods and manipulate an object's properties to utilize the features required to accomplish a task.

For more information about the Windows Script Host object model, see the Windows Script Host Object Model page at the Microsoft Web site (http://www.microsoft.com/).

For general information about Windows scripting, see the Windows Script Technologies Web site at the Microsoft Web site (http://www.microsoft.com/), and Microsoft Windows Resource Kits Web site (http://www.microsoft.com/).


Windows Script Host overview

You can use Windows Script Host to run scripts by clicking a script file on the Windows desktop or by typing the name of a script file at the command prompt. Similar to Microsoft Internet Explorer, Windows Script Host serves as a controller of ActiveX scripting engines. Unlike Internet Explorer, Windows Script Host has very low memory requirements and is ideal for both interactive and non-interactive scripting, such as logon scripting and administrative scripting.

There are two versions of the Windows Script Host: a Windows-based version (Wscript.exe), which provides a property sheet for setting script properties, and a command-prompt-based version (Cscript.exe), which provides command-line switches for setting script properties. You can run either of these by typing Wscript.exe or Cscript.exe at the command prompt.

Previously, the only native scripting language supported by the Windows operating system was that of batch files. Although batch language is fast and small, its features are limited compared to VBScript and JScript. For example, the ability to control program flow was not built into the batch language. Today, the Windows Script Host architecture allows you to take advantage of these powerful scripting languages, although support is still provided for batch files.

This version of WSH adds several areas of new functionality:

  • Improved argument handling. Handling and documenting command-line arguments is now simpler. For more information, see What's New in WSH 5.6 at the Microsoft Web site (http://www.microsoft.com/)
  • Remote scripting. You can load a script onto several remote computer systems which you can then run at the same time.
  • A running process is an object. You can sink events, access standard I/O streams, and share environment variables with other processes.
  • Flexible working directory. You can determine and modify the path of the current working directory of the active process.
  • Improved script security. The new script security model makes it safer to distribute and run scripts. For more information, see Windows Script (http://www.microsoft.com/), Microsoft Windows Resource Kits Web site (http://www.microsoft.com/)., and Security and Windows Script Host (http://www.microsoft.com/).


Run Windows Script Host

Microsoft Windows Graphic

To run Windows Script Host

Click the task that you want to perform.

To start a script so that it runs in a Windows environment

  1. Open Command Prompt.
  2. Type: wscript [ScriptName] [//B] [//D] [//E:Engine] [//H:CScript | //H:WScript] [//I] [//Job:Identifier] [//Logo | //NoLogo] [//S] [//T:Number] [//X] [//?] [ScriptArguments]

Parameters

ScriptName
Specifies the path and file name of the script file.
//B
Specifies batch mode, which does not display alerts, scripting errors, or input prompts.
//D
Starts the debugger.
//E:Engine
Specifies the engine that is used to run the script.
//H:cscript
Registers Cscript.exe as the default script host for running scripts.
//H:wscript
Registers Wscript.exe as the default script host for running scripts. This is the default.
//I
Specifies interactive mode, which displays alerts, scripting errors, and input prompts. This is the default and the opposite of //B.
//Job:Identifier
Runs the job identified by Identifier in a .wsf script file.
//Logo
Specifies that the Windows Script Host banner is displayed in the console before the script runs. This is the default and the opposite of //Nologo.
//Nologo
Specifies that the Windows Script Host banner is not displayed before the script runs.
//S
Saves the current command-prompt options for the current user.
//T:Number
Specifies the maximum time the script can run (in seconds). You can specify up to 32,767 seconds. The default is no time limit.
//X
Starts the script in the debugger.
//?
Displays available command parameters and provides help for using them.
ScriptArguments
Specifies the arguments passed to the script. Each script argument must be preceded by a slash (/).

Remarks

  • XOX
  • XOX
  • Each parameter is optional; however, you cannot specify script arguments without specifying a script. If you do not specify a script or any script arguments, Wscript.exe displays the Windows Script Host Settings dialog box, which you can use to set global scripting properties for all scripts that Wscript.exe runs on the local computer.
  • The //T parameter prevents excessive running of scripts by setting a timer. When the time exceeds the specified value, WScript interrupts the script engine and ends the process.
  • Windows script files usually have one of the following file name extensions: .wsf, .vbs, .js.
  • If you double-click a script file with an extension that has no association, the Open With dialog box appears. Select Wscript or Cscript, and then select Always use this program to open this file type. This registers Wscript.exe or Cscript as the default script host for files of this file type.
  • You can set properties for individual scripts. See Related Topics for more information.
  • Windows Script Host can use .wsf script files. Each .wsf file can use multiple scripting engines and perform multiple jobs.

To start a script so that it runs in a command-line environment

  1. Open Command Prompt.
  2. Type: cscript [ScriptName] [//B] [//D] [//E:Engine] [//H:CScript | //H:WScript] [//I] [//Job:Identifier] [//Logo | //NoLogo] [//S] [//T:Number] [//X] [//U] [//?] [ScriptArguments]

Parameters

ScriptName
Specifies the path and file name of the script file.
//B
Specifies batch mode, which does not display alerts, scripting errors, or input prompts.
//D
Starts the debugger.
//E:Engine
Specifies the engine that is used to run the script.
//H:cscript
Registers Cscript.exe as the default script host for running scripts.
//H:wscript
Registers Wscript.exe as the default script host for running scripts. This is the default.
//I
Specifies interactive mode, which displays alerts, scripting errors, and input prompts. This is the default and the opposite of //B.
//Job:Identifier
Runs the job identified by Identifier in a .wsf script file.
//Logo
Specifies that the Windows Script Host banner is displayed in the console before the script runs. This is the default and the opposite of //Nologo.
//Nologo
Specifies that the Windows Script Host banner is not displayed before the script runs.
//S
Saves the current command-prompt options for the current user.
//T:Number
Specifies the maximum time the script can run (in seconds). You can specify up to 32,767 seconds. The default is no time limit.
//U
Specifies Unicode for input and output that is redirected from the console.
//X
Starts the script in the debugger.
//?
Displays available command parameters and provides help for using them. This is the same as typing Cscript.exe with no parameters and no script.
ScriptArguments
Specifies the arguments passed to the script. Each script argument must be preceded by a slash (/).

Remarks

  • XOX
  • XOX
  • Each parameter is optional; however, you cannot specify script arguments without specifying a script. If you do not specify a script or any script arguments, Cscript.exe displays the Cscript.exe syntax and the valid host options.
  • The //T parameter prevents excessive running of scripts by setting a timer. When the run time exceeds the specified value, CScript interrupts the script engine and ends the process.
  • Windows script files usually have one of the following file name extensions: .wsf, .vbs, .js.
  • You can set properties for individual scripts. See Related Topics for more information.
  • Windows Script Host can use .wsf script files. Each .wsf file can use multiple scripting engines and perform multiple jobs.
  • If you double-click a script file with an extension that has no association, the Open With dialog box appears. Select Wscript or Cscript, and then select Always use this program to open this file type. This registers Wscript.exe or Cscript as the default script host for files of this file type.
  • You can set properties for individual scripts. See Related Topics for more information.
  • Windows Script Host can use .wsf script files. Each .wsf file can use multiple scripting engines and perform multiple jobs.
XOX

Related Topics


Run Windows Script Host samples

Microsoft Windows graphic

To run Windows Script Host samples

  1. Open the Command Prompt.
  2. Type the following:

    cscript samples folder\script name

    Where:

    samples folder is the path to the folder into which you downloaded the samples.

    script name is the name of the sample script you want to run, including the file name extension (for example, .js or .vbs).

    For example, if you saved the samples to C:\Samples, and you wanted to run the Network.vbs sample, you would type:

    cscript c:\sample\network.vbs

Notes

  • XOX
  • XOX
  • You must download the Windows Script Host sample files from the Microsoft Windows Script Technologies home page at the Microsoft Web site (http://www.microsoft.com/) before you can run them.
  • You can also double-click the sample script file to run a script using the Wscript.exe script host.


Set global properties for all scripts that are run with the Windows-based script host

Microsoft Windows graphic

To set global properties for all scripts that are run with the Windows-based script host

  1. Click Start, and then click Run
    2. .
  2. In the Open box, type wscript, and then click OK. The Windows Script Host Settings dialog box appears.
  3. Select the Stop script after specified number of seconds check box.
  4. In the seconds box, enter the time limit you want to place on all scripts.

Notes

  • XOX
  • With one setting, you can set properties for all scripts that are run with the Windows-based script host. Every script that is run with this host automatically uses these settings.


Set properties for individual scripts that are run with the Windows-based script host

Microsoft Windows graphic

To set properties for individual scripts that are run with the Windows-based script host

  1. Open Windows Explorer. Browse to the folder with the script whose properties you want to set, and right-click it.
  2. Select Properties, and then click the Script tab.
  3. Select the Stop script after specified number of seconds check box.
  4. In the seconds box, enter the time limit you want to place on this script.

Notes

  • XOX
  • XOX
  • These settings override global settings.
  • After clicking OK, a command file is created that binds the property settings to the script. It has the file name extension .wsh. You can use this command file as an alternate script file to run the script.

For more information, see the Windows Script Technologies Web site at the Microsoft Web site (http://www.microsoft.com/).